package mainpackage;

import engine.ani.Animation;
import engine.skill.SkillManager;
import java.util.Vector;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import ui.UiInterFace;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * <p>Title: 显示类</p>
 * <p>Description: �绘制游戏相关内容</p>
 * <p>Copyright: Copyright (c) 2010</p>
 * <p>Company: </p>
 * @author hlw
 * @version 1.0
 */
public class MainView {
	public static void drawTouchRect(Graphics g, int[][] touchrect) {
		if (true)
			return;
		if (touchrect != null && touchrect.length > 0) {
			g.setColor(0xff0000);
			for(int i=0;i<touchrect.length;i++) {
				int[] rect = touchrect[i];
				if (rect != null)
					g.drawRect(rect[0], rect[1], rect[2], rect[3]);
			}
		}
	}
    //用于一次载入img封装文件头减少IO操作使用后释放掉
    //常驻内存图片数组

//    public Image[] imgStaticArray = null;
    //影子图片
    public static Image imgShadow = null;
    //光标
    public static MainView instance = null;
    //游戏动画容器
    private Vector gameAnimation = null;
    //光标XY坐标
    private int iAniCursorX;
    private int iAniCursorY;
    //光标锁定索引
    private int shCursorIndex;
    //光标动画
    public static Animation aniCursor;
    //开始播放闪屏
    public static boolean blStartScreenFlash = false;
    //震屏开关
    public static boolean blStartScreenShake = false;
    public static int iShakeIndex = 0;
    public int[] aniCursorState = null;
    public boolean bStartIntoBattle = false;
    public String sIntoBattle = null;
    public int iPlace;

    public MainView() {
        instance = this;
        //动画文件容器初始化
        this.gameAnimation = new Vector(Constant.GAME_ANIMATION_NUMS);
        try {
            this.imgShadow = ResManager.createImage(90000072, Constant.RES_PUBLIC_FINAL, Constant.RES_UI_PATH, false, -1);
            this.imgShadow = Tools.makeTransparent(this.imgShadow, 70);
            this.aniCursor = ResManager.loadAnimation(Constant.RES_PLAYER_CURLOCK_ANI_PATH, Constant.RES_PUBLIC_FINAL, false);
            aniCursorState = new int[5];
        } catch (Exception ex) {
            if (Constant.DEBUG) {
                ex.printStackTrace();
            }
        }
    }

    public static MainView getInstance() {
        return instance;
    }
    //游戏总体绘制方法

    public void draw(byte gameState, Graphics g) {
        try {
            if (!MainLogic.getInstance().uiPackage.bShowBAG) {
                switch (gameState) {
                    case Constant.GAME_UI_ROAM:
                        this.drawRoam(g);
                        break;
                    case Constant.GAME_UI_NPC_TALK:
                        this.drawRoam(g);
                        MainLogic.getInstance().uiInterFace.npcTalk.drawNPCTalk(MainCanvas.backGraphics);
                        break;
                    //UI 登录界面
                    case Constant.GAME_UI_LOADING:
                        MainLogic.getInstance().uiInterFace.drawLoading(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_TEAM_INFO:
                        MainLogic.getInstance().uiInterFace.team.drawTeamInfo(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_VIEW_OTHER_PLAYER:
                        this.drawRoam(g);
                        MainLogic.getInstance().uiInterFace.drawLockPlayer(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_LOOK_OTHERPLAYER://查看其他玩家
                        MainLogic.getInstance().uiInterFace.drawOtherPlayerLooked(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_LOGO:
                        MainLogic.getInstance().uiLogin.drawLogo(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_OPTION_LIST:
                        MainLogic.getInstance().uiLogin.drawOptionList(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_OVER:
                        MainLogic.getInstance().uiLogin.drawOver(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_LOGIN:
                        MainLogic.getInstance().uiLogin.drawLogin(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_SERVER_LIST:
                        MainLogic.getInstance().uiLogin.drawServerList(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_CREATE_ROLE:
                        MainLogic.getInstance().uiLogin.drawCreateRole(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_ROAM_MENU:
                        //#if NOKIA_S40V3 || NORMAL_240_400 || MOT0 || K790
                        //#else
                        this.drawRoam(g);
                        //#endif
                        MainLogic.getInstance().uiInterFace.drawRoamMenu(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_ACCEPT_TASK:
                        MainLogic.getInstance().uiInterFace.npcTalk.drawTask(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_PACKAGE:
                        MainLogic.getInstance().uiPackage.drawPackage(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_EQUIPMENT:
                        MainLogic.getInstance().uiPackage.drawEquip(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_SKILL:
                        MainLogic.getInstance().uiEquipment.drawSkill(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_EXCHANGE:
                        this.drawRoam(g);
                        MainLogic.getInstance().uiEquipment.drawExchange(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_GAMESET:
                        MainLogic.getInstance().uiEquipment.drawGameset(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_OPEN_SCREEN:
                        MainLogic.getInstance().uiLogin.drawOpenScreen(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_CHAT:
                        MainLogic.getInstance().uiEquipment.drawChat(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_CHAT_SECOND:
                        MainLogic.getInstance().uiEquipment.drawChat(MainCanvas.backGraphics);
                        MainLogic.getInstance().uiEquipment.drawChatSecond(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_SMILE:
                        MainLogic.getInstance().uiEquipment.drawSmile(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_CHAT_SET:
                        MainLogic.getInstance().uiEquipment.drawChatSet(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_CONNECTION_AGAIN:
                        MainLogic.getInstance().uiEquipment.drawConnecAgain(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_TEAM_ANSWER:
                        this.drawRoam(g);
                        MainLogic.getInstance().uiInterFace.team.drawTeamAnswer(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_TASK_LIST:
                        MainLogic.getInstance().uiInterFace.npcTalk.drawTaskList(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_TONG_SKILL:
                        this.drawRoam(g);
                        MainLogic.getInstance().uiInterFace.tong.drawTongSkill(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_CREATE_TONG:
                        MainLogic.getInstance().uiInterFace.tong.drawCreateTong(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_TONG_LIST:
                        MainLogic.getInstance().uiInterFace.tong.drawTongList(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_TONG_MEMBER_LIST:
                        MainLogic.getInstance().uiInterFace.tong.drawTongMemberList(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_TONG_INFO:
                        MainLogic.getInstance().uiInterFace.tong.drawTongInfo(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_TONG_BUILDING:
                        drawRoam(g);
                        MainLogic.getInstance().uiInterFace.tong.drawTongBuilding(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_PET_COMPOSE:
                        MainLogic.getInstance().uiInterFace.pet.drawPetCompose(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_PET_EQUIP:
                        UiInterFace.pet.drawPetEquip(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_GAMESET_QUICKEYS:
                        UiInterFace.gameSet.drawQuickSet(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_SEND_EMAIL:
                        MainLogic.getInstance().uiEquipment.drawSendEmail(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_RECEIVE_EMAIL:
                        MainLogic.getInstance().uiEquipment.drawReceiveEmail(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_OPERATION_EMAIL:
                        MainLogic.getInstance().uiEquipment.drawReceiveEmail(MainCanvas.backGraphics);
                        MainLogic.getInstance().uiEquipment.drawOperationEmail(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_VIEW_EMAIL:
                        MainLogic.getInstance().uiEquipment.drawViewEmail(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_MERIDIANS:
                        MainLogic.getInstance().uiEquipment.drawMeridians(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_MAP_WORLD:
                        MainLogic.getInstance().uiEquipment.drawMapWorld(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_NOTICE_LIST:
                        MainLogic.getInstance().uiEquipment.drawNoticeList(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_ITEMS_COMPOSE:
                        //物品合成
                        MainLogic.getInstance().uiInterFace.equipment.drawItemsCompose(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_ITEMS_STRENGTHEN:
                        //物品强化
                        MainLogic.getInstance().uiInterFace.equipment.drawItemsStrengthen(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_ITEMS_DECOMPOSE:
                        MainLogic.getInstance().uiInterFace.equipment.drawItemsDecompose(MainCanvas.backGraphics);
                        //物品分解
                        break;
                    case Constant.GAME_UI_EQUIP_OPERATION:
                        //物品打孔镶嵌
                        MainLogic.getInstance().uiInterFace.equipment.drawEquipOperation(MainCanvas.backGraphics);
                        break;
                    //好友列表
                    case Constant.GAME_UI_FRIEND_LIST:
                        MainLogic.getInstance().uiInterFace.friend.drawFriendList(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_STORE_SOLD:
                        //出售
                        this.drawRoam(g);
                        break;
                    case Constant.GAME_UI_STORE_BUY:
                        //购买
                        UiInterFace.store.drawStoreBuy(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_TRADE:
                        //玩家交易
                        UiInterFace.store.drawTrade(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_TRADE_ANSWER:
                        this.drawRoam(g);
                        UiInterFace.store.drawTradeAnswer(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_WAREHOUSE:
                        this.drawRoam(g);
                        UiInterFace.store.drawWareHouse(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_PLAYER_INFO:
                        UiInterFace.property.drawPlayerInfo(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_PROPERTY_ADD_POINT:
                        UiInterFace.property.drawPropertyAddPoint(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_REVIVE:
                        drawRoam(g);
                        MainLogic.getInstance().uiInterFace.drawRevive(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_EQUIP_REPAIR:
                        drawRoam(g);
                        MainLogic.getInstance().uiInterFace.npcTalk.drawRepairEquip(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_CONTEST_ANSWER:
                        drawRoam(g);
                        MainLogic.getInstance().uiInterFace.drawContest(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_TONG_MENU:
                        drawRoam(g);
                        MainLogic.getInstance().uiInterFace.tong.drawTongMenu(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_NEAR_PLAYER_LIST:
                        MainLogic.getInstance().uiInterFace.drawNearPlayerList(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_PET_POWER_STRENGTHEN:
                        MainLogic.getInstance().uiInterFace.pet.drawPetPowerStrength(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_TRANSFER_LIST:
                        MainLogic.getInstance().uiInterFace.npcTalk.drawTransferList(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_APPLY_TONG_LIST:
                        MainLogic.getInstance().uiInterFace.tong.drawApplyTongList(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_TASK_AUTO_FIND_PATH:
                        drawRoam(g);
                        MainLogic.getInstance().uiInterFace.npcTalk.drawTaskAutoFindPath(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_HELP:
                        MainLogic.getInstance().uiLogin.drawHelp(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_ABOUT:
                        MainLogic.getInstance().uiLogin.drawAbout(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_SET:
                        MainLogic.getInstance().uiLogin.drawSet(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_UPDATE:
                        MainLogic.getInstance().uiLogin.drawUpdate(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_QUESTION:
                        MainLogic.getInstance().uiInterFace.drawQuestion(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_INGOT_STORE:
                        MainLogic.getInstance().uiInterFace.store.drawIngotStore(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_WAGE_STORE:
                        MainLogic.getInstance().uiInterFace.store.drawWageStore(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_INGOT_RECORD:
                        MainLogic.getInstance().uiInterFace.store.drawIngotRecord(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_PUNCH_CLOCK:
                        MainLogic.getInstance().uiInterFace.drawPunchClock(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_FUNC_DESC:
                        MainLogic.getInstance().uiInterFace.npcTalk.drawFuncDesc(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_BUFFER_LIST:
                        MainLogic.getInstance().uiInterFace.property.drawBufferList(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_FUNC_SETTING:
                        MainLogic.getInstance().uiInterFace.gameSet.drawFuncSetting(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_QUICK_OPTION:
                        drawRoam(g);
                        MainLogic.getInstance().uiInterFace.quickOption.drawQuickOption(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_PLAYER_TOP:
                        MainLogic.getInstance().uiInterFace.property.drawPlayerTop(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_PLAYER_STALL:
                        MainLogic.getInstance().uiInterFace.store.drawPlayerStall(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_HANGUP:
                        MainLogic.getInstance().uiInterFace.property.drawHangUp(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_CHANGE_PASSWD:
                        drawRoam(g);
                        MainLogic.getInstance().uiInterFace.drawChangePasswd(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_NETWORK_SELECT:
                        MainLogic.getInstance().uiLogin.drawNetWorkSelect(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_CHARGE:
                        MainLogic.getInstance().uiInterFace.gameSet.drawCharge(MainCanvas.backGraphics);
                        break;
                    case Constant.GAME_UI_CHARGE_LIST:
                        MainLogic.getInstance().uiInterFace.gameSet.drawChargeList(MainCanvas.backGraphics);
                        break;
                }
            } else {
                MainLogic.getInstance().uiPackage.drawPackage(MainCanvas.backGraphics);
            }
            if (MainLogic.getInstance().uiInterFace.sysMessage.bShowCheckItem) {
                MainLogic.getInstance().uiInterFace.sysMessage.drawCheckItem(MainCanvas.backGraphics);
            }
            //提示信息绘制
            if (MainLogic.getInstance().uiInterFace.sysMessage.bShowPopUpMessage) {
                MainLogic.getInstance().uiInterFace.sysMessage.drawShowMessage(MainCanvas.backGraphics);
                return;
            }
            //显示公告
            if (MainLogic.getInstance().uiInterFace.sysMessage.bShowNotice) {
                MainLogic.getInstance().uiInterFace.sysMessage.drawNotice(MainCanvas.backGraphics);
            }
            //引导
            if (MainLogic.getInstance().uiInterFace.sysMessage.bShowGuide) {
                MainLogic.getInstance().uiInterFace.sysMessage.drawGuide(MainCanvas.backGraphics);
            }
            //画引导红框
            if (MainLogic.getInstance().uiInterFace.sysMessage.isDrawRect) {
                MainLogic.getInstance().uiInterFace.sysMessage.drawDrawRect(MainCanvas.backGraphics);
            }

            //队伍物品roll点
            if (MainLogic.getInstance().uiInterFace.team.bShowRollPopUp) {
                MainLogic.getInstance().uiInterFace.team.drawItemRoll(MainCanvas.backGraphics);
            }
            //联网提示
            if (LocalMsgManager.bInHttpConnect) {
                LocalMsgManager.getInstance().drawHttpConnectWait(MainCanvas.backGraphics);
            }
            //高级界面底色
            if (!MainCanvas.bInCanvas) {
                g.setColor(0x000000);
                g.fillRect(Constant.UI_START_X, Constant.UI_START_Y, Constant.DRAW_WIDTH, Constant.DRAW_HEIGHT);
                return;
            }
            ResManager.BL_RECEIVE_NET_ANIMATION = true;
            if (this.bStartIntoBattle) {//显示玩家正在受到攻击
                this.drawByAttack(g);
            }
//            if (Constant.again_connection) {
//                g.setColor(0x000000);
//                g.fillRect(0, 0, Constant.DRAW_WIDTH, Constant.DRAW_HEIGHT);
//                Tools.drawShadowString(g, (byte) 2, "重新连接服务",
//                        (Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth("重新连接服务")) / 2, 50, 0xffffff, 0x000000);
//                Tools.drawShadowString(g, (byte) 2, "器请耐心等待",
//                        (Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth("器请耐心等待")) / 2,
//                        55 + Constant.FONT_SMALL.getHeight(), 0xffffff, 0x000000);
//            }
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
//        Integer key = new Integer(gameState);
//        int[][] touch = (int[][]) MainCanvas.s_uiTouch.get(key);
//        g.setClip(0, 0, 360, 640);
//        if (touch != null && touch.length > 0) {
//        	g.setColor(0xff0000);
//        	for (int i=0;i<touch.length;i++) {
//        		int[] rect = touch[i];
//        		if (rect != null) {
//        			g.drawRect(rect[0], rect[1], rect[2], rect[3]);
//        		}
//        	}
//        }
    }

    /**
     * 绘制漫游界面下内容
     * @param g
     */
    //光标播放控制
//    private int iAniCountIndex = 0;
    public void drawRoam(Graphics g) {
        //绘制底层地图
        MainLogic.gameMap.drawMap(g, MainLogic.gameMap.iMapViewOffsetX, MainLogic.gameMap.iMapViewOffsetY, Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT);
        if (MainLogic.getInstance().uiEquipment.isopenset[22]) {
            makeShake();
            //绘制黑屏
            this.drawFlash(g);
        }
//        //绘制光标
        this.drawCursorAni(g);
//        //绘制动画
        this.drawAnimations(g);
        //绘制鼠标
        //#if NOKIA_S60V5
         MainLogic.getInstance().uiInterFace.drawRoamPoint(g);
        //#endif
        //绘制锁定
        //绘制天空层
        MainLogic.gameMap.drawSky(g, MainLogic.gameMap.iMapWorldOffsetX, MainLogic.gameMap.iMapWorldOffsetY, Constant.SCREEN_WIDTH, Constant.SCREEN_HEIGHT);
        //绘制动画文件
        // g.drawImage(this.imgCuror, MainLogic.getInstance().gamePlayer.iPlayerX - this.gameMap.iMapWorldOffsetX - 21 - , MainLogic.getInstance().gamePlayer.iPlayerY - this.gameMap.iMapWorldOffsetY - 16, 0);
        //测试显示伤害数字
        if (MainLogic.damage.getSize() > 0) {
            MainLogic.damage.drawDamage(g);
        }
        //#if NOKIAN73 || NOKIA_S40V3  || NORMAL_240_400 || MOT0 || K790
        //#else
        if (MainLogic.getInstance().uiEquipment.isopenset[18]) {
            MainLogic.getInstance().uiInterFace.drawWeather(g);
        }
        //#endif
        //ui界面显示
        MainLogic.getInstance().uiInterFace.drawRoamUI(g);
    }

    public void drawFlash(Graphics g) {
        if (SkillManager.iSkillFalshNums <= 0) {
            return;
        }
        if (SkillManager.iSkillFalshNums > 0) {
            blStartScreenFlash = !blStartScreenFlash;
        } else {
            blStartScreenFlash = false;
//        if(!blStartScreenFlash)
//           return;

        }
        g.setColor(0xffffff);
        g.fillRect(-20, -20, Constant.SCREEN_WIDTH + 40, Constant.SCREEN_HEIGHT + 40);
        SkillManager.iSkillFalshNums -= 1;
    }

    public void makeShake() {
        if (SkillManager.iSkillShakeNums <= 0) {
            return;

        }
//        if (SkillManager.iSkillShakeNums > 0) {
//            blStartScreenShake = !blStartScreenShake;
//        } else {
//            blStartScreenShake = false;
////        if(!blStartScreenFlash)
////           return;
//
//        }
        iShakeIndex++;
        if (iShakeIndex == 1) {
            MainCanvas.backGraphics.translate(-8, 0);
        } else if (iShakeIndex == 2) {
            MainCanvas.backGraphics.translate(8, 0);
        } else if (iShakeIndex == 3) {
            MainCanvas.backGraphics.translate(0, -8);
        } else if (iShakeIndex == 4) {
            MainCanvas.backGraphics.translate(0, 8);
        }
        if (iShakeIndex > 4) {
            SkillManager.iSkillShakeNums -= 1;
            iShakeIndex = 0;
        }
    }
    //动画文件绘制

    private void drawAnimations(Graphics g) {
        if (MainLogic.getInstance().uiEquipment.isopenset[17]) {
            g.drawImage(this.imgShadow, MainLogic.getInstance().gamePlayer.iPlayerX - MainLogic.gameMap.iMapWorldOffsetX - 16,
                    MainLogic.getInstance().gamePlayer.iPlayerY - MainLogic.gameMap.iMapWorldOffsetY - 14, 0);
        }
        //绘制有优先级的精灵
        order = new int[1][3];
        order = getOrder();
        order = quickSort(order);
        drawOrder(g, order);
        //////////////////////////
//        //绘制npc
//        MainLogic.getInstance().gameNpcArray.drawNpc(g, MainLogic.gameMap.iMapWorldOffsetX, MainLogic.gameMap.iMapWorldOffsetY);
//        //绘制npc
//        MainLogic.getInstance().gameOtherplayerArray.drawOther(g, MainLogic.gameMap.iMapWorldOffsetX, MainLogic.gameMap.iMapWorldOffsetY);
//        //绘制其他玩家
//        MainLogic.getInstance().gamePlayer.show(g, MainLogic.gameMap.iMapWorldOffsetX, MainLogic.gameMap.iMapWorldOffsetY);
        //绘制技能光效
        this.drawSkillAni(g, MainLogic.gameMap.iMapWorldOffsetX, MainLogic.gameMap.iMapWorldOffsetY);
    }
    //排序画精灵
    public int[][] order = new int[1][3];//0精灵类型(1npc类型，2otherplayer类型，3玩家自己)，1精灵所在类型组中的索引，2当前精灵的Y坐标
    private int screenW = 50;
    private int screenH = 50;

    public int[][] getOrder() {
        int[][] temp = new int[1][3];
        int tempLen = 0;
        //玩家
        int length = MainLogic.getInstance().gameOtherplayerArray.shOtherIds.length - 1;
        //npc
        int npclength = MainLogic.getInstance().gameNpcArray.shNpcIds.length - 1;
        for (int i = npclength; i >= 0; i--) {
            if (MainLogic.getInstance().gameNpcArray.shNpcIds[i] != -1) {
                if (MainLogic.getInstance().gameNpcArray.iNpcXs[i] >= MainLogic.gameMap.iMapWorldOffsetX - screenW
                        && MainLogic.getInstance().gameNpcArray.iNpcXs[i] <= MainLogic.gameMap.iMapWorldOffsetX + screenW + Constant.SCREEN_WIDTH
                        && MainLogic.getInstance().gameNpcArray.iNpcYs[i] >= MainLogic.gameMap.iMapWorldOffsetY - screenH
                        && MainLogic.getInstance().gameNpcArray.iNpcYs[i] <= MainLogic.gameMap.iMapWorldOffsetY + screenH + Constant.SCREEN_HEIGHT) {
                    tempLen = temp.length - 1;
                    if (MainLogic.getInstance().gameNpcArray.strNpcResIds[i].equals(MainLogic.getInstance().gameNpcArray.strIds_send)) {
                        //235这里是传送动画，传送动画绘制在最底层
                        temp[tempLen][0] = 2;
                        temp[tempLen][1] = i;
                        temp[tempLen][2] = -400;
                        temp = resizeArray(temp);
                    } else {
                        temp[tempLen][0] = 2;
                        temp[tempLen][1] = i;
                        temp[tempLen][2] = MainLogic.getInstance().gameNpcArray.iNpcYs[i];
                        temp = resizeArray(temp);
                    }
                }
            }
        }
        npclength = MainLogic.getInstance().gameOtherplayerArray.shOtherIds.length - 1;
        for (int i = npclength; i >= 0; i--) {
            if (MainLogic.getInstance().gameOtherplayerArray.shOtherIds[i] != -1) {
                if (MainLogic.getInstance().gameOtherplayerArray.iOtherXs[i] >= MainLogic.gameMap.iMapWorldOffsetX - screenW
                        && MainLogic.getInstance().gameOtherplayerArray.iOtherXs[i] <= MainLogic.gameMap.iMapWorldOffsetX + screenW + Constant.SCREEN_WIDTH
                        && MainLogic.getInstance().gameOtherplayerArray.iOtherYs[i] >= MainLogic.gameMap.iMapWorldOffsetY - screenH
                        && MainLogic.getInstance().gameOtherplayerArray.iOtherYs[i] <= MainLogic.gameMap.iMapWorldOffsetY + screenH + Constant.SCREEN_HEIGHT) {
                    tempLen = temp.length - 1;
                    temp[tempLen][0] = 3;
                    temp[tempLen][1] = i;
                    temp[tempLen][2] = MainLogic.getInstance().gameOtherplayerArray.iOtherYs[i];
                    temp = resizeArray(temp);
                }
            }
        }
        if (MainLogic.getInstance().gamePlayer != null) {
            tempLen = temp.length - 1;
            temp[tempLen][0] = 4;
            temp[tempLen][1] = 0;
            temp[tempLen][2] = MainLogic.getInstance().gamePlayer.iPlayerY;
            temp = resizeArray(temp);
        }
        return temp;
    }
    //数组的排序
//    int[][] aaa = {
//        {1, 1, 10},//
//        {2, 1, 7},//
//        {3, 1, 12},//
//        {4, 1, 2},//
//        {5, 1, 6},//
//        {6, 1, 3},//
//        {7, 1, 14},//
//        {8, 1, 4},//
//        {9, 1, 8},//
//    };//4,6,8,5,2,9,1,3,7

    public static int[][] quickSort(int[][] arr) {
        int i, j;
        int[] temp = new int[arr[0].length];
        int[][] array = arr;
        //n个元素的数组进行n-1轮排序
        for (i = 0; i < array.length - 1; i++) {//由于数组最后一行不需要排序所以减2，否则减1
            //因为每一轮循环将确定一个数组元素的位置,
            //所以每一轮的比较次数将会递减
            for (j = 0; j < array.length - i - 1; j++) {
                if (array[j][2] > array[j + 1][2]) {
                    //如果第j个元素比它后面的相邻的元素大的话就交换
                    System.arraycopy(array[j], 0, temp, 0, array[j].length);
                    System.arraycopy(array[j + 1], 0, array[j], 0, array[j].length);
                    System.arraycopy(temp, 0, array[j + 1], 0, array[j].length);
                }
            }
        }
//        for (int c = 0; c < array.length; c++) {
//            Tools.printLog("好" + (c + 1) + " :: " + array[c][0] + " " + array[c][1] + " " + array[c][2] );
//        }
//        Tools.printLog("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
        //打印出排序后的数组
        return array;
    }

    public void drawOrder(Graphics g, int[][] order) {
        for (int i = 0; i < order.length; i++) {
            if (order[i][0] != 0) {
                if (order[i][0] == 2) {//gameNpcArray
                    //绘制npc
                    MainLogic.getInstance().gameNpcArray.drawNpc(g, order[i][1], MainLogic.gameMap.iMapWorldOffsetX, MainLogic.gameMap.iMapWorldOffsetY);
                } else if (order[i][0] == 3) {//gameOtherplayerArray
                    //绘制其他玩家
                    MainLogic.getInstance().gameOtherplayerArray.drawOther(g, order[i][1], MainLogic.gameMap.iMapWorldOffsetX, MainLogic.gameMap.iMapWorldOffsetY);
                } else if (order[i][0] == 4) {//gamePlayer
                    //绘制玩家
                    MainLogic.getInstance().gamePlayer.show(g, MainLogic.gameMap.iMapWorldOffsetX, MainLogic.gameMap.iMapWorldOffsetY);
                }
            }
        }
    }
    //改变数组大小

    public int[][] resizeArray(int[][] array) {
        int len = array.length;
        int[][] tmp = array;
        array = new int[len + 1][3];
        for (int i = 0; i < len; i++) {
            System.arraycopy(tmp[i], 0, array[i], 0, 3);
        }
        return array;
    }
    //添加animation

    public void addAnimation(Animation aAnimation) {
        gameAnimation.addElement(aAnimation);
    }

    public void initCursorAni() throws Exception {
        try {
            if (this.aniCursor == null) {
                this.aniCursor = ResManager.loadAnimation(Constant.RES_PLAYER_CURLOCK_ANI_PATH, Constant.RES_PUBLIC_FINAL, false);
            }
        } catch (Exception ex) {
            throw ex;
        }
        this.iAniCursorX = 0;
        this.iAniCursorY = 0;
        this.shCursorIndex = -1;
    }

    /**
     * 绘制光标动画
     */
    public void drawCursorAni(Graphics g) {
        if (MainLogic.iLockedObjNumber[0][2] != -1) {
            ResManager.drawAnimation(this.aniCursor, aniCursorState, g, (int) (MainLogic.iLockedObjNumber[0][2] - MainLogic.gameMap.iMapWorldOffsetX), (int) (MainLogic.iLockedObjNumber[0][3] - MainLogic.gameMap.iMapWorldOffsetY), true);
        }
    }

    public void drawSkillAni(Graphics g, int x, int y) {
        MainLogic.getInstance().aSkillManager.drawSkillAni(g, x, y);//getSkillAni(i).show(g, x, y);
    }

    /*****************在屏幕中显示玩家正在受到攻击************************************************/
    public void initByAttack() {
        this.bStartIntoBattle = true;
        sIntoBattle = "您正在受到攻击";
        iPlace = 0;
    }

    public void drawByAttack(Graphics g) {
        if (MainLogic.getInstance().byGameState != Constant.GAME_UI_ROAM) {
            Tools.drawShadowString(g, (byte) 1, sIntoBattle, Constant.UI_START_X + Constant.DRAW_WIDTH - iPlace * 5, Constant.UI_START_Y + 30, 0xFF0000, 0x000000, g.RIGHT | g.TOP);
            iPlace++;
            if (iPlace > 20) {
                this.clearByAttack();
            }
        }
    }

    public void clearByAttack() {
        this.bStartIntoBattle = false;
        sIntoBattle = null;
    }
}
